package com.jfeat.am.module.wegou.api.crud;

import com.jfeat.am.common.crud.CRUDFilterResult;
import com.jfeat.am.module.wegou.api.patch.ProductStatus;
import com.jfeat.am.module.wegou.services.crud.filter.ProductFilter;
import com.jfeat.am.module.wegou.services.crud.service.ProductService;
import com.jfeat.am.module.wegou.services.persistence.model.Product;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import com.jfeat.am.module.wegou.services.domain.service.QueryProductService;
import com.jfeat.am.common.constant.tips.SuccessTip;
import com.jfeat.am.common.constant.tips.Tip;

import org.springframework.web.bind.annotation.RestController;
import com.jfeat.am.common.controller.BaseController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Map;


/**
 * <p>
 * 料理 api
 * </p>
 *
 * @author Code Generator
 * @since 2018-01-03
 */
@Api("料理")
@RestController
@RequestMapping("/api/restaurant")
public class ProductEndpoint extends BaseController {

    @Resource
    ProductService productService;

    @Resource
    QueryProductService queryProductService;


    @ApiOperation(value = "料理 新建料理",response = Product.class)
    @PostMapping("/{stireId}/product/")
    public Tip createProduct(@PathVariable long stireId, @RequestBody Product entity) {
        entity.setStoreId(stireId);
        entity.setStatus(ProductStatus.RISE.toString());
        return SuccessTip.create(productService.createMaster(entity));
    }

    @ApiOperation(value = "料理 查询料理详情",response = Product.class)
    @GetMapping("/{storeId}/product/{id}")
    public Tip getProduct(@PathVariable Long id) {
        return SuccessTip.create(productService.retrieveMaster(id));
    }

    @ApiOperation(value = "料理 修改料理信息",response = Product.class)
    @PutMapping("/{storeId}/product/{id}")
    public Tip updateProduct(@PathVariable Long id, @RequestBody Product entity) {
        entity.setId(id);
        return SuccessTip.create(productService.updateMaster(entity));
    }

    @ApiOperation(value = "料理 新建删除料理信息",response = Product.class)
    @DeleteMapping("/{storeId}/product/{id}")
    public Tip deleteProduct(@PathVariable Long id) {
        return SuccessTip.create(productService.deleteMaster(id));
    }


    @ApiOperation(value = "料理 查询料理 通过 typeName/zhTypeName 查询",response = Product.class)
    @GetMapping("/{stireId}/product")
    public Tip queryProducts(@PathVariable Long stireId,
                             Page<Map<String,Object>> page,
                             @RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                             @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                             @RequestParam(name = "status", required = false) String status,
                             @RequestParam(name = "typeName", required = false) String typeName,
                             @RequestParam(name = "zhTypeName", required = false) String zhTypeName,
                             @RequestParam(name = "name", required = false) String name,
                             @RequestParam(name = "zhName", required = false) String zhName,
                             @RequestParam(name = "productTypeId", required = false) Long productTypeId) {
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        page.setRecords(queryProductService.findProductByType(page,status, typeName, zhTypeName,name,zhName,productTypeId,stireId));
        return SuccessTip.create(page);
    }

    ///  暂时不需要提供   后续可能会用到
    /*@GetMapping
    //此方法可能需要自行添加需要的参数,按需要使用
    public Tip queryProducts(Page<Product> page,
                             @RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                             @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                             @RequestParam(name = "id", required = false) Long id,
                             @RequestParam(name = "product_typeId", required = false) Long product_typeId,
                             @RequestParam(name = "cover", required = false) String cover,
                             @RequestParam(name = "thumbnails", required = false) String thumbnails,
                             @RequestParam(name = "restaurantId", required = false) Long restaurantId,
                             @RequestParam(name = "name", required = false) String name,
                             @RequestParam(name = "zhName", required = false) String zhName,
                             @RequestParam(name = "details", required = false) String details,
                             @RequestParam(name = "sortNumber", required = false) Integer sortNumber,
                             @RequestParam(name = "status", required = false) String status,
                             @RequestParam(name = "price", required = false) BigDecimal price) {
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        Product product = new Product();
        product.setId(id);
        product.setProductTypeId(product_typeId);
        product.setCover(cover);
        product.setThumbnails(thumbnails);
        product.setRestaurantId(restaurantId);
        product.setName(name);
        product.setZhName(zhName);
        product.setDetails(details);
        product.setSortNumber(sortNumber);
        product.setStatus(status);
        product.setPrice(price);

        page.setRecords(queryProductService.findProductPage(page, product));

        return SuccessTip.create(page);
    }*/
}
